package main.chapter3.extend

fun main(args: Array<String>) {
    println("abc".multiply(16))
    println("cba" * 16)

    val string = "abc"
    string.b = "cde"
    println(string.b)
}

//String类的扩展方法
fun String.multiply(times: Int): String {
    val stringBuilder = StringBuilder()
    for (i in 0 until times) {
        stringBuilder.append(this)
    }
    return stringBuilder.toString()
}

//扩展属性
val String.a: String
    get() {
        return "abc"
    }

var String.b: String
    get() {
        return "bcd"
    }
    set(value) {
    }

//操作符重载
operator fun String.times(times: Int): String {
    val stringBuilder = StringBuilder()
    for (i in 0 until times) {
        stringBuilder.append(this)
    }
    return stringBuilder.toString()
}